<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>门店管理管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			checkSize();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				rules:{          
					remarks:{remarkCheck:true} ,
					master:{required:true,stringCheck:true} ,
					cnName:{required:true,cnName:true} ,
					address:{required:true,addr:true} 
	            },
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			
			jQuery.validator.addMethod("stringCheck", function(value, element) {
				return this.optional(element) || /^[\u4e00-\u9fa5]{2,10}$/.test(value);
			}, "请输入2-10个汉字");
			
			jQuery.validator.addMethod("addr", function(value, element) {
				return this.optional(element) ||  /^(?=.*[\u4e00-\u9fa5])[a-zA-Z\d\u4e00-\u9fa5]{5,40}$/.test(value);


			}, "请输入 5-40个字符，须含汉字，可带字母或数字");
			jQuery.validator.addMethod("cnName", function(value, element) {
				return this.optional(element) || /^(?=.*[\u4e00-\u9fa5])[a-zA-Z\d\u4e00-\u9fa5]{4,20}$/.test(value);

			}, "请输入4-20个字符，须含汉字，可带字母或数字");
			jQuery.validator.addMethod("remarkCheck", function(value,  
	                element, param) { 
				if(value.length>100){
					return false;
				} else{
					return true;
	            }
	        }, $.validator.format("字数超限"));
			$("#remarks").keyup(function(){
				checkSize();
			})
		});
		function checkSize(){
			var curLength=$("#remarks").val().length;
			if(curLength>200){
				$("#textLength").css("color","red");
				$("#textLength").text(curLength+"/200");
			}else{
				$("#textLength").css("color","");
				$("#textLength").text(curLength+"/200");
			}
		}
		
		function stgg(){
			$("#inputForm").valid();
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/sys/store/">门店管理列表</a></li>
		<li class="active"><a href="${ctx}/sys/store/form?id=${store.id}&pa=0">门店管理<shiro:hasPermission name="sys:store:edit">${not empty store.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="sys:store:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="store" action="${ctx}/sys/store/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>	
		<input type="hidden" name="pa" value="${pa}">	
		<div class="control-group ">
			<label class="control-label ">门店名称：</label>
			<div class="controls">
				<form:input path="cnName" htmlEscape="false" maxlength="20" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group ">
			<label class="control-label">门店类型：</label>
			<div class="controls">
				<form:select id="type" path="type" class="input-medium required" onchange="stgg()">
				<form:option value="" label="请选择门店类型"/>
			    <form:options items="${fns:getDictList('store_type')}" htmlEscape="false" itemValue="value" itemLabel="label"  /></form:select>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">门店区域：</label>
			<div class="controls">
				<form:select id="classify" path="classify" class="input-medium required" onchange="stgg()">
				<form:option value="" label="请选择门店区域"/>
			    <form:options items="${area}" htmlEscape="false" itemValue="id" itemLabel="name"/></form:select>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">门店联系人：</label>
			<div class="controls">
				<form:input path="master" htmlEscape="false" maxlength="50" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">门店联系人手机号：</label>
			<div class="controls">
				<form:input path="masterPhone" htmlEscape="false" maxlength="50" class="input-xlarge required phone"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">门店详细地址：</label>
			<div class="controls">
				<form:input path="address" htmlEscape="false" maxlength="255"  class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">门店介绍：</label>
			<div class="controls">
		        <span id="textLength" style="margin-top: 74px;position: absolute;line-height: 1; margin-left: 475px;color: red;">0/200</span>
				<form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="225" class="input-xxlarge "/>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="sys:store:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>